home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ */
- /* */
- /* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
- /* */
- /* */
- /* This module was written by Vince Perriello */
- /* (based heavily on a similar work by Wynn Wagner III) */
- /* with modifications done by Bob Hartman */
- /* */
- /* */
- /* BinkleyTerm Mail Session Initiator */
- /* */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
- /* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
- /* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
- /* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
- /* ARE ABLE TO REACH WITH THE AUTHORS. */
- /* */
- /* */
- /* The Authors can be reached at the following addresses: */
- /* */
- /* Robert C. Hartman Vincent E. Perriello */
- /* Spark Software VEP Software */
- /* 427-3 Amherst Street 111 Carroll Street */
- /* CS2032, Suite 232 Naugatuck, CT 06770 */
- /* Nashua, NH 03061 */
- /* */
- /* FidoNet 1:132/101 FidoNet 1:141/491 */
- /* Data (603) 888-8179 Data (203) 729-7569 */
- /* */
- /* Please feel free to contact us at any time to share your comments */
- /* about our software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include <string.h>
-
- #define WAZOO_SECTION
- #define MATRIX_SECTION
-
- #include "com.h"
- #include "xfer.h"
- #include "zmodem.h"
- #include "keybd.h"
- #include "sbuf.h"
- #include "sched.h"
- #include "externs.h"
- #include "prototyp.h"
-
- void b_session (was_initiator)
- int was_initiator;
- {
- long t1, t2, t3;
- unsigned char j, d;
- int k, i;
- char *c, *m[16];
- char buff[128];
- int got_a_char = 0; /* For 'dead silence'
- * timeout */
-
- mail_finished = 0;
-
- if (un_attended && fullscreen)
- {
- do_ready ("Connect");
- }
-
- /* Remove the old .REQ and .RSP files */
- for (i = 0; i < 10; i++)
- {
- if (alias[i].Net == 0)
- break;
- sprintf (buff, "%s%04x%04x.REQ", CurrentNetFiles, alias[i].Net, alias[i].Node);
- unlink (buff);
-
- sprintf (buff, "%04x%04x.RSP", alias[i].Net, alias[i].Node);
- unlink (buff);
- }
-
- remote_capabilities = 0;
- if (was_initiator)
- goto initiate_outbound;
- /*
- * INBOUND -- meaning we were connected to by another system.
- */
- /* First a five second delay, or a char is found */
- t2 = timerset (500);
-
- t1 = timerset (1000); /* 10 secs silence T.O. */
- i = 0;
-
- /* As long as we have carrier, and 5 seconds is not up, and no */
- /* special chars have been received, just continue looping */
-
- while (CARRIER && (!timeup (t2)) && (i == 0))
- {
- switch (i = (unsigned char) (PEEKBYTE () & 0x7f))
- {
- case 0x7f: /* No char available */
- i = 0; /* i = 0 keeps us here */
- break;
-
- case CR:
- case LV:
- case ' ':
- case TSYNC & 0x7f:
- case YOOHOO & 0x7f:
- case ENQ:
- case ESC:
- break; /* Magic characters */
-
- default: /* Non-magic character */
- ++got_a_char; /* Say we saw something */
- TIMED_READ (0); /* Then eat it up */
- i = 0; /* And stay in the loop */
- }
- }
-
- sprintf (buff, "\r\r* Network Address %d:%d/%d.%d Using %s\r\n",
- alias[0].Zone, boss_net, boss_node,
- (boss_net == alias[0].Net) ? 0 : alias[0].Node, ANNOUNCE);
-
- sendbanner (buff);
-
- t2 = timerset (BBStimeout); /* 20 second timeout */
-
- if (strlen (BBSbanner) != 0) /* If BBS name spec'ed, */
- {
- SENDBYTE ('\r'); /* make sure user gets */
- SENDBYTE ('\n'); /* a full cr/lf... */
-
- sendbanner (BBSbanner);
-
- SENDBYTE ('\r'); /* make sure user gets */
- SENDBYTE ('\n'); /* a full cr/lf... */
- }
-
- if (!mail_only)
- {
- sendbanner (BBSwelcome);
- }
-
- play_banner:
- if (mail_only) /* If no BBS allowed, */
- c = noBBS; /* tell human to git */
- else c = BBSesc; /* or hit ESC for BBS */
-
- sendbanner (c);
-
- get_handshake:
- for (k = 0; k < num_ext_mail; k++)
- {
- m[k] = ext_mail_string[k]; /* UUCP handshake */
- }
-
- while (CARRIER && (!timeup (t2)))
- {
-
- if (got_ESC ()) /* Manual abort? */
- {
- DTR_OFF (); /* Yes, drop carrier */
- timer (10);
- return;
- }
-
- i = PEEKBYTE () & 0xff; /* Get the next char */
-
- switch (i)
- {
- case 0xff: /* No character there */
- if (!got_a_char && timeup (t1) && !mail_only)
- goto spawnBBS; /* 10 secs silence = human! */
- continue;
-
- case YOOHOO: /* Looks like an Opus */
- got_a_yoohoo:
-
- ++got_a_char; /* Note that we got this */
-
- if (no_WaZOO) /* If we're not WaZOO, */
- {
- i = TIMED_READ (0); /* Eat the YooHoo */
- continue;
- }
-
- CLEAR_OUTBOUND (); /* End noisy banner now */
-
- if (YooHoo_Receiver ()) /* Get its HELLO string */
- {
- last_type (1, remote_zone, remote_net, remote_node);
- ++hist.mail_calls;
- sb_move (historywin, HIST_MAIL_ROW, HIST_COL);
- sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
- sb_puts (historywin, junk);
-
- WaZOO (0); /* And do WaZOO!!! */
- return;
- }
- else if (!hup)
- goto get_handshake; /* bad hello, try again */
- else return;
-
- case TSYNC: /* Looks like an FTSC */
- /* See if we get anything within 2 seconds, if not, then it */
- /* is FTSC. If we get another TSYNC, it also means FTSC. */
- /* BUT, if we get a YOOHOO, then we can do WaZOO, and it */
- /* just means that we missed the first YOOHOO - lucky us. */
-
- CLEAR_INBOUND ();
- CLEAR_OUTBOUND (); /* End noisy banner now */
- if (no_WaZOO) /* If we're not WaZOO, */
- goto do_FTSC; /* Don't bother waiting */
-
- t3 = timerset (200); /* Set for 2 seconds */
- d = 0;
- while (CARRIER && (!timeup (t3)) && (!d))
- {
- if ((i = PEEKBYTE ()) >= 0)
- {
- switch (i)
- {
- case YOOHOO:
- goto got_a_yoohoo;
-
- case TSYNC:
- d = 1;
- break;
-
- default:
- TIMED_READ (0);
- }
- }
- }
- do_FTSC:
- if (CARRIER)
- {
- last_type (2, -1000, 0, 0);
- ++hist.mail_calls;
- sb_move (historywin, HIST_MAIL_ROW, HIST_COL);
- sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
- sb_puts (historywin, junk);
-
- if (un_attended && fullscreen)
- sb_show ();
-
- FTSC_receiver (0);
- }
- return;
-
- case CR:
- i = TIMED_READ (0); /* Eat the CR */
- ++got_a_char; /* Note that we got this */
- goto play_banner; /* Play the banner again */
-
- case ESC: /* This will be for BBS */
- if (!mail_only) /* If BBS operation OK, */
- goto spawnBBS; /* go do it... */
-
- default:
- ++got_a_char; /* Note that we got this */
- i = TIMED_READ (0) & 0xff; /* Eat the character */
- for (k = 0; k < num_ext_mail; k++)
- {
- if (i != *(m[k]++)) /* Does this match next? */
- m[k] = ext_mail_string[k]; /* No, reset pointer */
- else if (!*m[k]) /* End of UUCP string? */
- goto spawn_UUCP; /* Yes, start UUCP */
- }
- }
- }
- spawnBBS:
- if (CARRIER && !mail_only)
- {
- last_type (3, 0, 0, 0);
-
- BBSexit ();
- }
- return;
- spawn_UUCP:
- if (CARRIER)
- {
- last_type (4, 0, 0, 0);
- UUCPexit (lev_ext_mail[k]);
- }
- return;
-
- /*
- * OUTBOUND -- meaning call was made by us.
- */
-
- initiate_outbound:
-
- last_type (1, remote_zone, remote_net, remote_node);
- if (Whack_CR ())
- {
- return;
- }
- t1 = timerset (3000); /* set 30 second timeout */
- j = 'j'; /* Something that will not
- * trip the states below */
- t3 = timerset (50); /* Wait for .5 second of
- * clear line */
- while (!timeup (t1) && CARRIER) /* till then or CD lost */
- {
- if (!no_WaZOO && !no_WaZOO_Session) /* If we're WaZOO, */
- SENDBYTE (YOOHOO); /* try YooHoo? */
- SENDBYTE (TSYNC); /* Always try FSC */
-
- t2 = timerset (300); /* Time between sending
- * startup seq */
- while (CARRIER && (!timeup (t2)))
- {
- i = TIMED_READ (0);
-
- /* Because Fido v12 has a tendency to echo the YooHoo and throw */
- /* off the value of j which we use later on. We just ignore it */
- if ((i & 0x7f) == (YOOHOO & 0x7f))
- continue;
-
- switch (i)
- {
- case ENQ:
- if (no_WaZOO || no_WaZOO_Session) /* If we're not WaZOO, */
- break; /* ignore it */
-
- if (YooHoo_Sender ()) /* Send Hello packet, */
- {
- WaZOO (1);
- return;
- }
- break;
-
- case 0x00:
- case 0x01:
- case 'C':
- if (j == 'C')
- {
- FTSC_sender (0);
- return;
- }
-
- if (timeup (t3))
- {
- timer (1);
- if (CHAR_AVAIL ())
- {
- /* If it is SEAlink stuff, do it */
- i = TIMED_READ (0);
- if ((i == 0) || (i == 1) || (i == 'C') || (i == NAK))
- {
- FTSC_sender (0);
- return;
- }
-
- t3 = timerset (50);
- j = 'j';
- }
- }
- break;
-
- case 0xfe:
- case 0xfffe:
- if (j == 0x01)
- {
- FTSC_sender (0);
- return;
- }
- break;
-
- case 0xff:
- case 0xffff:
- if (j == 0x00)
- {
- FTSC_sender (0);
- return;
- }
- break;
-
- case NAK:
- if (j == NAK)
- {
- FTSC_sender (0);
- return;
- }
- break;
- }
-
- if ((i != (int) 0xffff) && (i != 0xff))
- {
- /* We got a character */
- CLEAR_INBOUND ();
-
- if (timeup (t3))
- {
- /* We already saw a clear line */
- j = (unsigned char) (i & 0xff);
- }
- else
- {
-
- /*
- * We haven't seen a clear line yet, so reset the timer. We do
- * this so that opening screens that contain many 'C'
- * characters don't confuse us into FSC001. FSC001 can only
- * start after .5 second of clear line is seen.
- */
- t3 = timerset (50);
- }
- }
- }
- }
- }
-
- /*
- * Send banner-type lines to remote. Since strange modems like Courier HST
- * have a propensity for thinking they are connected when talking to a dial
- * tone (but do leave CTS down just to screw us up) we have to use a timeout
- * to figure out if we are in trouble, and if so, we drop DTR to make the
- * bogus carrier go away.
- *
- */
-
- void sendbanner (string)
- char *string;
- {
- long t1;
- register char c;
-
- t1 = timerset (600); /* 60 seconds max to put out
- * banner */
-
- while (!timeup (t1) && CARRIER)
- {
- if (got_ESC ()) /* Manual abort? */
- break; /* Use failure logic */
-
- if (!OUT_FULL ())
- {
- c = *string++;
- if (!c || c == 0x1a) /* Test for end */
- return;
- SENDBYTE (c);
- }
- }
-
- /*
- * If we get here we had trouble. Drop DTR now to hopefully get out of
- * this trouble. Flush outbound. Pause for 1 second.
- */
-
- DTR_OFF ();
- CLEAR_OUTBOUND ();
-
- timer (10);
-
- CLEAR_INBOUND ();
- }
-
-
-
- void b_init ()
- {
- got_arcmail = got_packet = got_mail = sent_mail = 0;
- remote_zone = remote_net = remote_node = remote_point = 0;
- Netmail_Session = remote_capabilities = mail_finished = 0;
- CurrentNetFiles = DEFAULT.sc_Inbound;
- }
-